package org.orbis.memoryblock.appendix;

import java.nio.charset.Charset;

import org.orbis.memoryblock.BlockPackage;

public class AppendixPackage implements BlockPackage{
	private int strLength;
	private String string;
	private byte[] stringbyte;
	private int cluster;
	
	private AppendixPackage() {}
	
	public static AppendixPackage setPackage() {
		AppendixPackage pkg = new AppendixPackage();
		pkg.stringbyte = new byte[0];
		return pkg;
	}
	
	public AppendixPackage cluster(int cluster) {
		this.cluster = cluster;
		return this;
	}
	
	public AppendixPackage strLen(int strLength){
		this.strLength = strLength;
		return this;
	}
	
	public AppendixPackage string(String string){
		this.string = string;
		this.stringbyte = string.getBytes(Charset.forName("UTF-8"));
		this.strLength = stringbyte.length;
		return this;
	}
	
	public AppendixPackage stringRaw(byte[] stringb) {
		this.stringbyte = stringb;
		this.strLength = stringb.length;
		this.string = new String(stringb, Charset.forName("UTF-8"));
		return this;
	}
	
	public String getString(){
		return string;
	}
	
	public int getStrLength(){
		return strLength;
	}
	
	public byte[] getStringRaw() {
		return stringbyte;
	}
	
	public int getCluster() {
		return cluster;
	}

	@Override
	public int length(){
		return STRLEN + stringbyte.length;
	}
}
